package com.quanyan.user.web;

import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.user.service.TaskEggService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by slong.guo on 2017/2/10.
 */

@RestController
@RequestMapping(value="/api/user/taskegg", method = RequestMethod.POST, produces = "application/json")
public class TaskEggController {
    private static final Logger logger = LoggerFactory.getLogger(TaskEggController.class);

    @Autowired
    private TaskEggService taskEggService;

    @RequestMapping(value="/list", method = RequestMethod.POST)
    public APIResponse eggList(@RequestBody Map map, HttpServletRequest request){
        Integer uid = (Integer) request.getAttribute("uid");
        if(uid == null){
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }
        return taskEggService.getTaskEggInfo(uid);
    }

    @RequestMapping(value="/doEggTask")
    public APIResponse doEggTask(@RequestBody Map map, HttpServletRequest request){
        Integer uid = (Integer) request.getAttribute("uid");
        if(uid == null){
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }

        return taskEggService.doEggTask(uid);
    }


}
